package com.ash.create;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @encoding : UTF-8
 * @Time : 2020/12/3 14:53
 * @Author : Chen Chao
 * @File : connection.com.ash.create.Test01.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * 创建表
 */
public class Test01 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        /*1.加载驱动，*/
        Class.forName("com.mysql.jdbc.Driver");

        /*2.获取连接对象*/
        /*2.1 url,中间空格都不能有*/
        String url = "jdbc:mysql://www.cc.com:3306/connection?characterEncoding=utf8" +
                "&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true&" +
                "allowPublicKeyRetrieval=true";
        /*2.2 用户名*/
        String user="root";
        /*2.3 密码*/
        String password="123456";
        /*2.4建立连接并打印连接*/
        Connection connection = DriverManager.getConnection(url, user, password);

        /*3.创建sql语句*/
        String sql="create table student(id int ,name  varchar(50),age int)";
        /*4.创建sql语句执行对象*/
        Statement statement = connection.createStatement();
        /*5.执行sql语句，DDL结果返回0*/
        int i = statement.executeUpdate(sql);
        System.out.println(i);

        /*6.关闭资源*/
        statement.close();
        connection.close();

    }
}
